<!DOCTYPE html>
<html>
<head>
    <title>WorkTool Message Sender</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
        }
        input[type="text"], textarea {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #45a049;
        }
        #response {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            white-space: pre-wrap;
        }
    </style>
</head>
<body>
    <h1>WorkTool Message Sender</h1>
    <div class="form-group">
        <label for="deviceId">Device ID:</label>
        <input type="text" id="deviceId" value="wtd1k5lm8q1eh0ijeq7gy3n9sl23cf1y">
    </div>
    <div class="form-group">
        <label for="roomId">Room ID:</label>
        <input type="text" id="roomId" value="软件开发简工">
    </div>
    <div class="form-group">
        <label for="message">Message:</label>
        <textarea id="message" rows="4">你好</textarea>
    </div>
    <div class="form-group">
        <label for="atList">At List (comma separated):</label>
        <input type="text" id="atList" placeholder="user1,user2">
    </div>
    <button onclick="sendMessage()">Send Message</button>
    <div id="response"></div>
    <div class="form-group">
        <button onclick="checkDeviceStatus()">Check Device Status</button>
    </div>

    <script>
        const apiBase = `${location.protocol}//${location.host}`;

        async function sendMessage() {
            const deviceId = document.getElementById('deviceId').value;
            const roomId = document.getElementById('roomId').value;
            const text = document.getElementById('message').value;
            const atList = document.getElementById('atList').value.split(',').filter(x => x);

            if (!deviceId || !roomId || !text) {
                alert('Please fill in all required fields');
                return;
            }

            const data = {
                deviceId,
                roomId,
                text,
                msgType: 1,
                atList
            };

            try {
                const response = await fetch(`${apiBase}/robot/sendMessage`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json'
                    },
                    body: JSON.stringify(data)
                });

                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }

                const result = await response.json();
                document.getElementById('response').textContent = 
                    JSON.stringify(result, null, 2);
            } catch (error) {
                document.getElementById('response').textContent = 
                    `Error: ${error.message}`;
                console.error('Error:', error);
            }
        }

        async function checkDeviceStatus() {
            const deviceId = document.getElementById('deviceId').value;
            
            if (!deviceId) {
                alert('Please enter device ID');
                return;
            }

            try {
                const response = await fetch(`${apiBase}/robot/robotInfo/get?robotId=${deviceId}`);
                const result = await response.json();
                document.getElementById('response').textContent = 
                    JSON.stringify(result, null, 2);
            } catch (error) {
                document.getElementById('response').textContent = 
                    `Error: ${error.message}`;
                console.error('Error:', error);
            }
        }
    </script>
</body>
</html> 